<%--
  Created by IntelliJ IDEA.
  User: cyrus
  Date: 2021/07/29
  Time: 16:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录</title>
    <style>
        .container {
            background-color: lightcyan;
            width: 300px;
            margin: 150px auto;
        }
    </style>
</head>
<body>
<div class="container">
    <form action="${pageContext.request.contextPath}/login" method="post">
        <div>
            <div><label for="username">用户名</label></div>
            <input type="text" id="username" name="username">
        </div>
        <div>
            <div><label for="password">密码</label></div>
            <input type="password" id="password" name="password">
        </div>
        <div>
            <div><label for="code">验证码</label></div>
            <input type="text" id="code" name="code">
            <img src="${pageContext.request.contextPath}/captcha" onclick="refreshCaptcha(this)">
        </div>
        <%--
            验证码：
                1. 在服务端生成(图片)，生成好了之后传递到客户端（存在到session里）
                2. 客户端提交的时候带上这个验证码，在服务端进行校验（和session中的验证码进行校验）
        --%>
        <button>登录</button>
        <a href="${pageContext.request.contextPath}/register.jsp">注册</a>
    </form>
    <c:if test="${not empty error}">
        <div style="color: red">${error}</div>
    </c:if>
</div>
<script>
    function refreshCaptcha(e){
        e.src = "${pageContext.request.contextPath}/captcha?time=" + new Date().getTime()
    }
</script>
</body>
</html>
